﻿using Easy.Domain.OrderAggregate;
using Easy.Infrastructure;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Easy.Api.Extensions
{
    public static class ServiceCollectionExtension
    {
        public static IServiceCollection AddMediatRServices(this IServiceCollection services)
        {
            services.AddTransient(typeof(IPipelineBehavior<,>), typeof(DomainContextTransactionBehavior<,>));
            return services.AddMediatR(typeof(Order).Assembly,typeof(Program).Assembly);
        }
        public static IServiceCollection AddDomainContext(this IServiceCollection services,Action<DbContextOptionsBuilder> action)
        {
            return services.AddDbContext<DomainContext>(action);
        }
        public static IServiceCollection AddMySqlDomainContext(this IServiceCollection services,string connectString)
        {
            return services.AddDomainContext(builder =>
            {
                builder.UseMySql(connectString,new MySqlServerVersion("5.7.24"));
            });
        }
    }
}
